﻿using UnityEngine;
using System.Collections;

public class CrocodileController2 : MonoBehaviour {
	public float speed = 10.0F;
	void Update() {
		if (transform.position.x <= -4.3f) {
			transform.position = new Vector2(-4.3f, transform.position.y);
		} else if (transform.position.x >= 4.3f) {
			transform.position = new Vector2(4.3f, transform.position.y);
		}

		Vector3 dir = Vector3.zero;
		dir.x = -Input.acceleration.y;
		dir.z = Input.acceleration.x;
		if (dir.sqrMagnitude > 1)
			dir.Normalize();
		
		dir *= Time.deltaTime;
		transform.Translate(dir * speed);
	}
}
